#include <stdio.h>

int main()
{
    // 创建文件夹
    // system("mkdir example_folder");

    // 创建文件
    FILE *file = fopen("example.txt", "w");
    if (file == NULL)
    {
        printf("Error creating file!\n");
        return 1;
    }

    // 写入内容到文件
    fprintf(file, "Hello, world!\n");
    fclose(file);

    // 追加内容到文件
    file = fopen("example.txt", "a");
    if (file == NULL)
    {
        printf("Error opening file for appending!\n");
        return 1;
    }
    fprintf(file, "This is appended content.\n");
    fclose(file);

    // 读取文本文件
    file = fopen("example.txt", "r");
    if (file == NULL)
    {
        printf("Error opening file for reading!\n");
        return 1;
    }

    char buffer[100];
    while (fgets(buffer, 100, file) != NULL)
    {
        printf("%s", buffer);
    }
    fclose(file);

    // 修改文件名
    if (rename("example.txt", "new_example.txt") != 0)
    {
        printf("Error renaming file!\n");
    }

    // 删除文件
    if (remove("new_example.txt") != 0)
    {
        printf("Error deleting file!\n");
    }

    // 删除文件夹
    // system("rmdir example_folder");

    return 0;
}